package WordCount;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

/**
 * @author 姜世钰
 * date: 2021/9/29 15:35
 **/
public class WordCountReducer extends Reducer<Text, IntWritable,Text,IntWritable> {
    @Override
    protected void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException {
//        super.reduce(key, values, context);
        int total = 0;//对values求和
        for (IntWritable value : values) {
            total +=value.get();    //value.get()是将IntWritable类型转换成int类型
        }
        context.write(key,new IntWritable(total));
    }
}
